import request from '@/utils/request';

/**
 *    用户API
 */
export default {
	// 获取忘记密码验证码
	getUserForgetPassCode(email) {
		return request('/user/forgetPassCode', { email }, 'get');
	},
	// 忘记密码
	userForgetPass(data) {
		return request('/user/forgetPass', data, 'post');
	},

	// 获取房源列表
	getHouses(pageNo, pageSize) {
		return request(`/user/list/${pageNo}/${pageSize}`, {}, 'get');
	},

	// 搜索房源
	searchHouses(keyword, pageNo, pageSize) {
		return request(`/user/searchHouse/${pageNo}/${pageSize}`, { keyword: keyword || '' }, 'post');
	},

	// 筛选房源
	filterHouses(filters, pageNo, pageSize) {
		return request(`/user/filterHouse/${pageNo}/${pageSize}`, filters, 'post');
	},

	// 搜索再筛选房源
	filterHousesByKey(conditions, pageNo, pageSize) {
		return request(`/user/filterHouseByKey/${pageNo}/${pageSize}`, conditions, 'post');
	},

	//通过id获取房源信息
	getHouseById(houseId, userId) {
		return request(`/user/getHouseById/${houseId}?userId=${userId}`, {}, 'get');
	},

	//获取个人信息
	getUserInfo() {
		return request('/user/userInfo', {}, 'get');
	},

	//修改个人信息
	updateUserInfo(data) {
		return request('/user/updateInfo', data, 'post');
	},

	//获取修改邮箱验证码
	getModifyEmailCode(email) {
		return request('/user/getUpdateEmailCode', { email }, 'get');
	},

	//修改邮箱
	updateEmail(data) {
		return request('/user/updateEmail', data, 'post');
	},

	//上传头像
	uploadLogo(data) {
		return request('/user/uploadLogo', data, 'post', {
			headers: {
				'Content-Type': 'multipart/form-data'
			}
		});
	},

	//修改密码
	modifyPass(data) {
		return request('/user/modifyPass', data, 'post');
	},

	//预约房源
	reserveHouse(data) {
		return request('/user/reserveHouse', data, 'post');
	},

	//创建会话
	createConversation(data) {
		return request('/chat/createConversation', data, 'post');
	},

	//发送消息
	sendMessage(data) {
		return request('/chat/send', data, 'post');
	},

	//获取该用户的所有会话
	getAllConversations(userId) {
		return request(`/chat/user/allConversations/${userId}`, {}, 'get');
	},

	//获取会话中所有的消息
	getAllMessages(conversationId) {
		return request(`/chat/messages/${conversationId}`, {}, 'get');
	},

	// 标记该会话中的消息为已读
	markMessagesAsRead(conversationId, viewerId) {
		return request(`/chat/markAsRead/${conversationId}/${viewerId}`, {}, 'put');
	},

	//获取用户所有收藏的房源
	getFavorites(pageNo, pageSize) {
		return request(`/user/myFavorites/${pageNo}/${pageSize}`, {}, 'get');
	},

	// 收藏房源
	addFavorite(houseId) {
		return request(`/user/addFavorite/${houseId}`, {}, 'post');
	},

	// 取消收藏房源
	removeFavorite(houseId) {
		return request(`/user/removeFavorite/${houseId}`, {}, 'delete');
	},

	//猜你喜欢
	// 猜你喜欢接口
	getGuessYouLike(pageNo, pageSize) {
		return request(
			`/user/recommendedHouses/${pageNo}/${pageSize}`,
			{},
			'get',
			{
				validateStatus: function (status) {
					// 认为 200-299 的状态码和 401 状态码都为成功
					return (status >= 200 && status < 300) || status === 401;
				}
			}
		);
	},

	//获取预约房源
	getReserveHouses(pageNo, pageSize) {
		return request(`/user/myAppointments/${pageNo}/${pageSize}`, {}, 'get');
	},

	//变更预约时间
	changeAppointmentTime(id,originalScheduleId,newScheduleId,newAppointmentDate) {
		return request('/user/changeTime', {  id,originalScheduleId,newScheduleId,newAppointmentDate}, 'post');
	},

	//取消预约
	cancelAppointment(id) {
		return request(`/user/cancelAppointment/${id}`, {}, 'post');
	},

	//获取房东档期
	getLandlordSchedules(landlordId) {
		return request(`/user/landlordSchedules/${landlordId}`, {}, 'get');
	},
};
